package com.virgo.common.utils;

import lombok.experimental.UtilityClass;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@UtilityClass
public class IValidateUtils {

	/**
	 * 验证是否是邮箱
	 * @param email 输入内容
	 * @return boolean
	 */
	public boolean email(String email) {
		String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		Pattern regex = Pattern.compile(check);
		Matcher matcher = regex.matcher(email);
		return matcher.matches();
	}

	/**
	 * 验证是否手机号
	 * @param mobileNumber 输入内容
	 * @return boolean
	 */
	public boolean mobile(String mobileNumber) {
		Pattern regex = Pattern.compile("^1[345789]\\d{9}$");
		Matcher matcher = regex.matcher(mobileNumber);
		return matcher.matches();
	}

	/**
	 * 验证是否URL地址
	 * @param urls 输入内容
	 * @return boolean
	 */
	public boolean httpUrl(String urls) {
		String regex = "(((https|http)?://)?([a-z0-9]+[.])|(www.))"
				+ "\\w+[.|\\/]([a-z0-9]{0,})?[[.]([a-z0-9]{0,})]+((/[\\S&&[^,;\u4E00-\u9FA5]]+)+)?([.][a-z0-9]{0,}+|/?)";//设置正则表达式

		Pattern pat = Pattern.compile(regex.trim());
		Matcher mat = pat.matcher(urls.trim());
		return mat.matches();
	}

	/**
	 * 验证是否QQ
	 * @param qq 输入内容
	 * @return boolean
	 */
	public boolean qq(String qq) {
		Pattern regex = Pattern.compile("^[1-9][0-9]{4,}$");
		Matcher matcher = regex.matcher(qq);
		return matcher.matches();
	}

	/**
	 * 验证是否身份证号
	 * @param id 输入内容
	 * @return boolean
	 */
	public boolean id(String id) {
		id = id.toLowerCase();
		Pattern regex = Pattern.compile("^\\d{15}(\\d{2}[0-9x])?$");
		Matcher matcher = regex.matcher(id);
		return matcher.matches();
	}

	/**
	 * 验证是否邮编
	 * @param zip 输入内容
	 * @return boolean
	 */
	public boolean zip(String zip) {
		Pattern regex = Pattern.compile("^\\d{6}$");
		Matcher matcher = regex.matcher(zip);
		return matcher.matches();
	}

	/**
	 * 验证是否座机号码
	 * @param phone 输入内容
	 * @return boolean
	 */
	public boolean phone(String phone) {
		Pattern regex = Pattern.compile("^((\\d{3,4})|\\d{3,4}-)?\\d{3,8}(-\\d+)*$");
		Matcher matcher = regex.matcher(phone);
		return matcher.matches();
	}

	/**
	 * 指定类型检查
	 * @param content 内容
	 * @param regex 匹配规则
	 * @return boolean
	 */
	public boolean check(String content,String regex) {
		content = content.trim().toLowerCase();
		regex = regex.trim();
		Pattern pat = Pattern.compile(regex.trim());
		Matcher mat = pat.matcher(content.trim());
		return mat.matches();
	}

	/**
	 * 密码校验
	 * @param password String
	 * @return boolean
	 */
	public boolean password(String password) {
		Pattern regex = Pattern.compile("^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\\\\(\\\\)])+$)([^(0-9a-zA-Z)]|[\\\\(\\\\)]|[a-zA-Z]|[0-9]){6,16}$");
		Matcher matcher = regex.matcher(password);
		return matcher.matches();
	}
}